extends Node2D

# 注释掉技能树相关代码，由玩家脚本处理
# var skill_tree_scene = preload("res://scenes/skill_tree.tscn")
# var skill_tree_instance = null
# @onready var skill_tree: Control = $CanvasLayer/SkillTree

var parallax_background_scene = preload("res://scenes/background/parallax_background.tscn")

func _ready() -> void:
	print("Main scene ready")  # 调试信息
	
	# 首先添加视差背景（确保它在场景最底层）
	add_parallax_background()
	
	# 添加初始物品
	var success = InventoryManager.add_item("1", 1)  # 添加裁星者
	
	# 添加调试脚本
	var debug_script = load("res://scripts/debug/debug_groups.gd").new()
	add_child(debug_script)
	
	# 注释掉技能树相关代码，由玩家脚本处理
	# if not skill_tree:
	# 	skill_tree_instance = skill_tree_scene.instantiate()
	# 	$CanvasLayer.add_child(skill_tree_instance)
	# 	print("不存在技能面板场景节点,尝试实例化")
	# else:
	# 	skill_tree_instance = skill_tree
	# 	print("已存在技能面板场景实例")
	
	# # 确保技能树初始不可见
	# if skill_tree_instance:
	# 	skill_tree_instance.visible = false
	# 	skill_tree_instance.set_process_input(false)
	
	print("添加物品: ", success)  # 调试信息

func _input(event):
	# 注释掉技能树相关代码，由玩家脚本处理
	# if event.is_action_pressed("ui_skill"):
	# 	toggle_skill_tree_visibility()
	pass
		
# 注释掉技能树相关代码，由玩家脚本处理
# func toggle_skill_tree_visibility():
# 	if skill_tree_instance:
# 		skill_tree_instance.visible = !skill_tree_instance.visible
# 		skill_tree_instance.set_process_input(skill_tree_instance.visible)
# 		
# 		# 不再调用grab_focus和release_focus
# 		
# 		print("技能树可见状态：", skill_tree_instance.visible)

# 添加视差背景
func add_parallax_background():
	var parallax_background = parallax_background_scene.instantiate()
	# 确保视差背景添加在场景最底层
	if get_child_count() > 0:
		add_child.call_deferred(parallax_background)
		move_child.call_deferred(parallax_background, 0)
	else:
		add_child(parallax_background)
	print("已添加视差背景，层级：", parallax_background.get_index())
